package com.example.demo2.service;

import com.example.demo2.bean.AnnouncementBean;
import com.example.demo2.dao.AnnouncementBeanDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnnouncementBeanService {

    @Autowired
    AnnouncementBeanDao dao;

    public List<AnnouncementBean> list(){
        List<AnnouncementBean> all = dao.findAll();
        return all;
    }

    public AnnouncementBean login(AnnouncementBean yourBean) {
        AnnouncementBean yourBean1 = dao.findOne(Example.of(yourBean)).orElse(null);
        return yourBean1;
    }

    public AnnouncementBean register(AnnouncementBean yourBean) {
        AnnouncementBean save = dao.save(yourBean);
        return save;
    }

    public AnnouncementBean findone(AnnouncementBean yourBean) {
        AnnouncementBean yourBean1 = dao.findOne(Example.of(yourBean)).orElse(null);
        return yourBean1;
    }

    public void deleteById(Integer id) {
        dao.deleteById(id);
    }

    public AnnouncementBean update(AnnouncementBean yourBean) {
        AnnouncementBean save = dao.save(yourBean);
        return save;
    }

    public AnnouncementBean addone(AnnouncementBean yourBean) {
        AnnouncementBean save = dao.save(yourBean);
        return save;
    }
}
